]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
unlockDialog: Add swipe gesture
authorFlorian Müllner <fmuellner@gnome.org>
Sun, 2 Feb 2020 11:23:32 +0000 (12:23 +0100)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Thu, 13 Feb 2020 15:01:25 +0000 (15:01 +0000)
Clicking or typing to reveal the auth prompt are good options for
mouse/keyboard workflows, but awkward on touch devices. Now that
we have SwipeTracker, adding corresponding gestures support is
easy, so do just that.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/972

js/ui/unlockDialog.js

index 51fe6253f6d57bd5889035df52d3cfa8bbd84e40..1816689a35e187b6a8ed0777a28c2a28a40695e7 100644 (file)
@@ -8,6 +8,7 @@ const Background = imports.ui.background;
 const Layout = imports.ui.layout;
 const Main = imports.ui.main;
 const MessageTray = imports.ui.messageTray;
+const SwipeTracker = imports.ui.swipeTracker;
 
 const AuthPrompt = imports.gdm.authPrompt;
 
@@ -436,6 +437,12 @@ var UnlockDialog = GObject.registerClass({
             this._setTransitionProgress(this._adjustment.value);
         });
 
+        this._swipeTracker = new SwipeTracker.SwipeTracker(
+            this, Shell.ActionMode.UNLOCK_SCREEN);
+        this._swipeTracker.connect('begin', this._swipeBegin.bind(this));
+        this._swipeTracker.connect('update', this._swipeUpdate.bind(this));
+        this._swipeTracker.connect('end', this._swipeEnd.bind(this));
+
         this._activePage = null;
 
         let tapAction = new Clutter.TapAction();
@@ -457,16 +464,16 @@ var UnlockDialog = GObject.registerClass({
         this._user = this._userManager.get_user(this._userName);
 
         // Authentication & Clock stack
-        let stack = new Shell.Stack();
+        this._stack = new Shell.Stack();
 
         this._promptBox = new St.BoxLayout({ vertical: true });
         this._promptBox.set_pivot_point(0.5, 0.5);
         this._promptBox.hide();
-        stack.add_child(this._promptBox);
+        this._stack.add_child(this._promptBox);
 
         this._clock = new Clock();
         this._clock.set_pivot_point(0.5, 0.5);
-        stack.add_child(this._clock);
+        this._stack.add_child(this._clock);
         this._showClock();
 
         this.allowCancel = false;
@@ -480,10 +487,10 @@ var UnlockDialog = GObject.registerClass({
         // Main Box
         let mainBox = new Clutter.Actor();
         mainBox.add_constraint(new Layout.MonitorConstraint({ primary: true }));
-        mainBox.add_child(stack);
+        mainBox.add_child(this._stack);
         mainBox.add_child(this._notificationsBox);
         mainBox.layout_manager = new UnlockDialogLayout(
-            stack,
+            this._stack,
             this._notificationsBox);
         this.add_child(mainBox);
 
@@ -656,6 +663,40 @@ var UnlockDialog = GObject.registerClass({
             this._authPrompt.cancel();
     }
 
+    _swipeBegin(tracker, monitor) {
+        if (monitor !== Main.layoutManager.primaryIndex)
+            return;
+
+        this._adjustment.remove_transition('value');
+
+        this._ensureAuthPrompt();
+
+        let progress = this._adjustment.value;
+        tracker.confirmSwipe(this._stack.height,
+            [0, 1],
+            progress,
+            Math.round(progress));
+    }
+
+    _swipeUpdate(tracker, progress) {
+        this._adjustment.value = progress;
+    }
+
+    _swipeEnd(tracker, duration, endProgress) {
+        this._activePage = endProgress
+            ? this._promptBox
+            : this._clock;
+
+        this._adjustment.ease(endProgress, {
+            mode: Clutter.AnimationMode.EASE_OUT_CUBIC,
+            duration,
+            onComplete: () => {
+                if (this._activePage === this._clock)
+                    this._maybeDestroyAuthPrompt();
+            },
+        });
+    }
+
     _onDestroy() {
         this.popModal();